package com.zsh.activities;

import java.util.ArrayList;
import java.util.List;

import com.zsh.adapters.FeaturesPagerAdapter;
import com.zsh.prototype.R;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class FeaturesActivity extends Activity {
	private ViewPager mViewPager;
	private FeaturesPagerAdapter mAdapter;
	private LinearLayout mLinearLayout;
	private LayoutInflater mLayoutInflater;
	private List<View> mLists;
	private ImageView[] points;

	private int current = 0;
	protected boolean mIsBackButtonPressed = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,      
                WindowManager.LayoutParams. FLAG_FULLSCREEN);
		setContentView(R.layout.activity_features);
		initView();
		initPoints();
	}

	private void initView() {
		mLayoutInflater = LayoutInflater.from(this);
		mViewPager = (ViewPager) this.findViewById(R.id.viewpager);
		mLists = new ArrayList<View>() {
			private static final long serialVersionUID = 6880200701537933028L;

			{
				add(mLayoutInflater.inflate(R.layout.feature_01, null));
				add(mLayoutInflater.inflate(R.layout.feature_02, null));
				add(mLayoutInflater.inflate(R.layout.feature_03, null));
				add(mLayoutInflater.inflate(R.layout.feature_04, null));
			}
		};

		mAdapter = new FeaturesPagerAdapter(mLists,this);
		mViewPager.setAdapter(mAdapter);

		mViewPager.setOnPageChangeListener(new MyOnPagerChangeListener());
	}
	
	private void initPoints() {
		mLinearLayout = (LinearLayout) this.findViewById(R.id.feature_ll);
		points = new ImageView[mLists.size()];
		for (int i = 0; i < mLists.size(); i++) {
			points[i] = (ImageView) mLinearLayout.getChildAt(i);
			points[i].setEnabled(false);
		}
		current = 0;
		points[current].setEnabled(true);
	}

	class MyOnPagerChangeListener implements OnPageChangeListener {
		@Override
		public void onPageScrollStateChanged(int arg0) {

		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {

		}

		@Override
		public void onPageSelected(int position) {
			points[position].setEnabled(true);
			points[current].setEnabled(false);
			current = position;
		}
	}
}
